﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-21-22:18
//  * @Description:
//  */

using Code.GameLogic.BaseClass;
using Code.GameLogic.Map;
using UnityEngine;

namespace Code.GameLogic.Common
{
    public class WayPointManager : AbsGameLogicManager
    {
        private static WayPointBo[] _wayPointBos = new WayPointBo[50];

        public void AddWayPoint(WayPointBo wayPointBo)
        {
            _wayPointBos[wayPointBo.Order] = wayPointBo;
        }

        public static WayPointBo GetWayPointBo(Vector3 vector3)
        {
            float temp = 10000;
            WayPointBo tempWayPointBo = null;
            foreach (WayPointBo wayPointBo in _wayPointBos)
            {
                if (wayPointBo is not null)
                {
                    float distance = Vector3.Distance(vector3, wayPointBo.Postion);
                    if (distance == 0) return wayPointBo;

                    if (temp < distance)
                    {
                        temp = distance;
                        tempWayPointBo = wayPointBo;
                    }
                }
            }

            return tempWayPointBo;
        }

        public static WayPointBo GetLastWayPoint(int nextWayPointOrder)
        {
            return _wayPointBos[nextWayPointOrder];
        }
    }
}